//
// Created by wangjunjun on 2023/10/25.
//

#ifndef SUBJECT_H
#define SUBJECT_H
#include "Observer.h"
#include <memory>
#include <vector>
#include <mutex>
class SubJect {
public:
    SubJect();
    ~SubJect();
public:
    void attach(std::shared_ptr<Observer> observer);
    void detach(std::shared_ptr<Observer> observer);
    void notify();
private:
    std::vector<std::weak_ptr<Observer>> m_Observers;
    std::mutex m_mtx; // 互斥锁
};


#endif //SUBJECT_H
